﻿#region

using System.ComponentModel;
using System.Web.Mvc;

#endregion

namespace HouseHoldBudget.Framework.Mvc
{
    public class ModelBinder : DefaultModelBinder
    {
        #region Instance Methods

        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = base.BindModel(controllerContext, bindingContext);
            if (model is MvcModelBase) ((MvcModelBase) model).BindModel(controllerContext, bindingContext);
            return model;
        }

        protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
        {
            base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
        }

        protected override PropertyDescriptorCollection GetModelProperties(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            bindingContext.PropertyFilter = pred;
            var values = base.GetModelProperties(controllerContext, bindingContext);
            return values;
        }

        protected override object GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder)
        {
            var value = base.GetPropertyValue(controllerContext, bindingContext, propertyDescriptor, propertyBinder);
            return value;
        }

        protected bool pred(string target)
        {
            return true;
        }

        #endregion
    }
}